package org.github.core.spring.restful.json;

import java.util.Collection;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import static java.util.Collections.emptyList;

/**
 * JSON of array.
 *
 * @param <E> element
 * @author JYD_XL
 * @see java.io.Serializable
 * @see java.util.function.Supplier
 */
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
public class JSONArray<E> extends JSONBase implements JSON {
  /** 数据 */
  @NotNull
  private Collection<E> data = emptyList();

  @Override
  public String toString() {
    return super.toString();
  }

  /**
   * Generator.
   */
  @NotNull
  public static <E> JSONArray<E> of() {
    return new JSONArray<>();
  }

  /**
   * Generator.
   */
  @NotNull
  public static <E> JSONArray<E> of(@NotNull Collection<E> data) {
    return new JSONArray<>(data);
  }
}
